/*
 * @Author: gao_m3
 * @Date: 2020-09-03 08:52:51
 * @LastEditors: wei_jt@ecidi.com
 * @LastEditTime: 2021-09-24 11:24:02
 * @Descripttion: 
 */
import request from '@/utils/request'
import { getClientConfig } from '@/api/app'

export function setConfig (data) {
  return request({
    url: '/sys-system/client',
    method: 'put',
    data: data,
  })
}
export function getConfig (settingsJSON, val, form) {
  return getClientConfig().then((res) => {
    Object.assign(settingsJSON, res.data)
    if (res.data.additionalInformation.indexOf(val) > -1) {
      Object.assign(form, JSON.parse(res.data.additionalInformation)[val])
      if (val == 'loginStrategy') {
        form.accessTokenValidity = res.data.accessTokenValidity / 60
        if (!JSON.parse(res.data.additionalInformation)[val].loginWays) {
          form.loginWays = []
        } else {
          form.loginWays = JSON.parse(res.data.additionalInformation)[val].loginWays
        }
        form.loginErrorLockTime = (JSON.parse(res.data.additionalInformation)[val].loginErrorLockTime) / 60
        form.sessionValidTime = (JSON.parse(res.data.additionalInformation)[val].sessionValidTime) / 60
      }
    }
  })
}
/** 根据id获取应用详情 */
export function getClient (id) {
  return request({
    url: '/sys-system/clients',
    method: 'get',
    params: {

    }
  })
}
/** 获取配置信息 */
export function getServerConfig () {
  return request({
    url: '/sys-system/serverConfig',
    method: 'get'
  })
}
/** 更新配置信息 */
export function setServerConfig (data) {
  return request({
    url: '/sys-system/serverConfig',
    method: 'put',
    data: data
  })
}
//获取文件上传配置
export function getFileUploadConfig () {
  return request({
    url: '/sys-system/fileUploadConfig',
    method: 'get'
  })
}
//更新文件上传配置信息
export function setFileUploadConfig (data) {
  return request({
    url: '/sys-system/fileUploadConfig',
    method: 'put',
    data: data
  })
}
export function getExtraData (data) {
  return request({
    url: '/sys-system/oauth/clients',
    method: 'get',
    params: data
  })
}
//短信模板分页查询
export function getTemplateList (params) {
  return request({
    url: '/sys-msg/smsTemplate/page',
    method: 'get',
    params: params
  })
}
//映射查询
export function getMapping (params) {
  return request({
    url: '/sys-msg/smsTemplateMapping/list',
    method: 'get',
    params: params
  })
}
//短信模板修改
export function editTemplate (data) {
  return request({
    url: '/sys-msg/smsTemplateMapping',
    method: 'put',
    data: data
  })
}
//短信模板添加
export function addTemplate (data) {
  return request({
    url: '/sys-msg/smsTemplateMapping',
    method: 'post',
    data: data
  })
}
